package  org.fantasy.cpp.core.pojo;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Table;

import  org.fantasy.cpp.core.annotation.Field;
import  org.fantasy.common.util.StringUtil;

@Table("QUERY_PAGE")
public class QueryPage {

	/**
	 * 普通页面
	 */
	public static final Long PAGE_TYPE_NORMAL = 1l;

	@Id
	@Column("page_id")
	@Field(desc = "页面id", nullable = false)
	private Long pageId;

	@Column("parent_id")
	@Field(desc = "父页面id", nullable = true)
	private Long parentId;

	@Column("query_id")
	@Field(desc = "查询id", nullable = false)
	private Long queryId;

	@Column("table_id")
	@Field(desc = "表格id", nullable = false)
	private Long tableId;

	@Column("templet_id")
	@Field(desc = "模板id", nullable = false)
	private Long templetId;

	@Column("module_id")
	@Field(desc = "模块id", nullable = false)
	private Long moduleId;

	@Column("chart_id")
	@Field(desc = "图表id", nullable = true)
	private Long chartId;

	@Column("page_name")
	@Field(desc = "页面名称", nullable = false, maxlenth = 64)
	private String pageName;

	@Column("page_type_id")
	@Field(desc = "页面类型", nullable = false)
	private Long pageTypeId;

	@Column("page_desc")
	@Field(desc = "页面描述", nullable = true, maxlenth = 1024)
	private String pageDesc;

	@Column("page_url")
	@Field(desc = "查询提交", nullable = true, maxlenth = 256)
	private String pageUrl;

	@Column("page_code")
	@Field(desc = "页面编码", nullable = true, maxlenth = 64)
	private String pageCode;

	@Column("auto_query")
	@Field(desc = "自动查询", nullable = false)
	private Long autoQuery;

	@Column("cell_custom")
	@Field(desc = "自定义单元", nullable = true, maxlenth = 128)
	private String cellCustom;

	@Column("row_custom")
	@Field(desc = "自定义行", nullable = true, maxlenth = 128)
	private String rowCustom;

	@Column("toolbar")
	@Field(desc = "工具条", nullable = true, maxlenth = 512)
	private String toolbar;

	@Column("button")
	@Field(desc = "按钮", nullable = true, maxlenth = 512)
	private String button;

	@Column("pagination")
	@Field(desc = "是否分页", nullable = true)
	private Long pagination;

	@Column("lock_head")
	@Field(desc = "锁定表头", nullable = true)
	private Long lockHead;

	@Column("main_script")
	@Field(desc = "查询页面脚本", nullable = true)
	private String mainScript;

	@Column("result_script")
	@Field(desc = "结果页面脚本", nullable = true)
	private String resultScript;

	@Column("create_date")
	@Field(desc = "创建日期", nullable = false)
	private Timestamp createDate;

	@Column("var_name")
	@Field(desc = "引用名", nullable = true, maxlenth = 32)
	private String varName;

	@Column("state")
	@Field(desc = "状态", nullable = false, maxlenth = 3)
	private String state;

	public Long getTempletId() {
		return templetId;
	}

	public void setTempletId(Long templetId) {
		this.templetId = templetId;
	}

	public Long getModuleId() {
		return moduleId;
	}

	public void setModuleId(Long moduleId) {
		this.moduleId = moduleId;
	}

	public Long getQueryId() {
		return queryId;
	}

	public void setQueryId(Long queryId) {
		this.queryId = queryId;
	}

	public Long getTableId() {
		return tableId;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public void setTableId(Long tableId) {
		this.tableId = tableId;
	}

	public Long getPagination() {
		return pagination;
	}

	public void setPagination(Long pagination) {
		this.pagination = pagination;
	}

	/**
	 * Return the unique identifier of this class
	 * 
	 * @hibernate.id generator-class="vm" column="PAGE_ID"
	 */
	public Long getPageId() {
		return pageId;
	}

	public Long getChartId() {
		return chartId;
	}

	public void setChartId(Long chartId) {
		this.chartId = chartId;
	}

	/**
	 * Set the unique identifier of this class
	 * 
	 * @param id
	 *            the new ID
	 */
	public void setPageId(Long id) {
		this.pageId = id;
	}

	/**
	 * Return the value associated with the column: PAGE_URL
	 */
	public String getPageUrl() {
		return pageUrl;
	}

	/**
	 * Set the value related to the column: PAGE_URL
	 * 
	 * @param pageUrl
	 *            the PAGE_URL value
	 */
	public void setPageUrl(String pageUrl) {
		this.pageUrl = pageUrl;
	}

	public Long getAutoQuery() {
		return autoQuery;
	}

	public void setAutoQuery(Long autoQuery) {
		this.autoQuery = autoQuery;
	}

	public String getCellCustom() {
		return cellCustom;
	}

	public String getButton() {
		return button;
	}

	public void setButton(String button) {
		this.button = button;
	}

	public void setCellCustom(String cellCustom) {
		this.cellCustom = cellCustom;
	}

	public String getRowCustom() {
		return rowCustom;
	}

	public void setRowCustom(String rowCustom) {
		this.rowCustom = rowCustom;
	}

	public String getToolbar() {
		return toolbar;
	}

	public void setToolbar(String toolbar) {
		this.toolbar = toolbar;
	}

	public Long getLockHead() {
		return lockHead;
	}

	public void setLockHead(Long lockHead) {
		this.lockHead = lockHead;
	}

	public Long getPageTypeId() {
		return pageTypeId;
	}

	public void setPageTypeId(Long pageTypeId) {
		this.pageTypeId = pageTypeId;
	}

	/**
	 * Return the value associated with the column: PAGE_NAME
	 */
	public String getPageName() {
		return pageName;
	}

	/**
	 * Set the value related to the column: PAGE_NAME
	 * 
	 * @param pageName
	 *            the PAGE_NAME value
	 */
	public void setPageName(String pageName) {
		this.pageName = pageName;
	}

	/**
	 * Return the value associated with the column: PAGE_CODE
	 */
	public String getPageCode() {
		return pageCode;
	}

	/**
	 * Set the value related to the column: PAGE_CODE
	 * 
	 * @param pageCode
	 *            the PAGE_CODE value
	 */
	public void setPageCode(String pageCode) {
		this.pageCode = pageCode;
	}

	public Timestamp getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Timestamp createDate) {
		this.createDate = createDate;
	}

	/**
	 * Return the value associated with the column: RESULT_SCRIPT
	 */
	public String getResultScript() {
		return resultScript;
	}

	/**
	 * Set the value related to the column: RESULT_SCRIPT
	 * 
	 * @param resultScript
	 *            the RESULT_SCRIPT value
	 */
	public void setResultScript(String resultScript) {
		this.resultScript = resultScript;
	}

	/**
	 * Return the value associated with the column: PARENT_ID
	 */
	public Long getParentId() {
		return parentId;
	}

	/**
	 * Set the value related to the column: PARENT_ID
	 * 
	 * @param parentId
	 *            the PARENT_ID value
	 */
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	/**
	 * Return the value associated with the column: PAGE_DESC
	 */
	public String getPageDesc() {
		return pageDesc;
	}

	/**
	 * Set the value related to the column: PAGE_DESC
	 * 
	 * @param pageDesc
	 *            the PAGE_DESC value
	 */
	public void setPageDesc(String pageDesc) {
		this.pageDesc = pageDesc;
	}

	/**
	 * Return the value associated with the column: MAIN_SCRIPT
	 */
	public String getMainScript() {
		return mainScript;
	}

	/**
	 * Set the value related to the column: MAIN_SCRIPT
	 * 
	 * @param mainScript
	 *            the MAIN_SCRIPT value
	 */
	public void setMainScript(String mainScript) {
		this.mainScript = mainScript;
	}

	public boolean equals(Object obj) {
		if (null == obj)
			return false;
		if (!(obj instanceof  org.fantasy.cpp.core.pojo.base.BaseQueryPage))
			return false;
		else {
			 org.fantasy.cpp.core.pojo.base.BaseQueryPage mObj = ( org.fantasy.cpp.core.pojo.base.BaseQueryPage) obj;
			if (null == this.getPageId() || null == mObj.getPageId())
				return false;
			else
				return (this.getPageId().equals(mObj.getPageId()));
		}
	}

	public int hashCode() {
		return pageId.hashCode();
	}

	public String getVarName() {
		return varName;
	}

	public void setVarName(String varName) {
		this.varName = varName;
	}

	@Override
	public String toString() {
		return StringUtil.bean2String(this);
	}

	// many to one
	private QueryTemplet queryTemplate;
	private List<QueryItem> queryItems = new ArrayList<QueryItem>();
	private QueryConfig queryConfig;
	private TableConfig tableConfig;
	private ChartConfig chartConfig;
	private List<QueryPage> childPages = new ArrayList<QueryPage>();

	/**
	 * 是否分页
	 * 
	 * @return
	 */
	public boolean isPage() {
		return new Long(1).equals(pagination);
	}

	public boolean getIsPage() {
		return isPage();
	}

	public QueryTemplet getQueryTemplate() {
		return queryTemplate;
	}

	public void setQueryTemplate(QueryTemplet queryTemplate) {
		this.queryTemplate = queryTemplate;
	}

	public List<QueryItem> getQueryItems() {
		return queryItems;
	}

	public void setQueryItems(List<QueryItem> queryItems) {
		this.queryItems = queryItems;
	}

	public QueryConfig getQueryConfig() {
		return queryConfig;
	}

	public void setQueryConfig(QueryConfig queryConfig) {
		this.queryConfig = queryConfig;
	}

	public TableConfig getTableConfig() {
		return tableConfig;
	}

	public void setTableConfig(TableConfig tableConfig) {
		this.tableConfig = tableConfig;
	}

	public ChartConfig getChartConfig() {
		return chartConfig;
	}

	public void setChartConfig(ChartConfig chartConfig) {
		this.chartConfig = chartConfig;
	}

	public List<QueryPage> getChildPages() {
		return childPages;
	}

	public void setChildPages(List<QueryPage> childPages) {
		this.childPages = childPages;
	}

	/**
	 * 取得查询项
	 * 
	 * @param id
	 * @return
	 */
	public QueryItem getQueryItem(Long itemId) {
		for (QueryItem item : queryItems) {
			if (itemId.equals(item.getItemId())) {
				return item;
			}
		}
		return null;
	}

	public boolean getIsLockHead() {
		return new Long(1) == getLockHead();
	}
}